@isTest(SeeAllData=true)
private class Test_MobileAppRequestSearchExtension {

    private static Request__c newRequest;
    
    public static void createData() {
        Account newAccount = new Account();
        newAccount.Name = 'New Account';
        newAccount.Mobile__c = '1122452';
        insert newAccount;
        
        Contact newContact = new Contact();
        newContact.FirstName = 'Test';
        newContact.LastName = 'Test';
        newContact.AccountId = newAccount.Id;
        insert newContact;
        
        Share_Ownership__c newShareOwnership = new Share_Ownership__c();
        newShareOwnership.Company__c = newAccount.Id;
        newShareOwnership.Shareholder__c = newContact.Id;
        newShareOwnership.Share_Profit__c = 50;
        insert newShareOwnership;
        
        Transaction_Types__c newTransacrionType = new Transaction_Types__c();
        newTransacrionType.Application_Package__c = 'Service Letter';
        newTransacrionType.Application_Type__c = 'Certificate';
        newTransacrionType.Transaction_Description__c = 'Certificate of Incorporation';
        newTransacrionType.Name = 'Certificate - Share Certificate';
        newTransacrionType.isMobile__c = True;
        newTransacrionType.Active__c = True;
        insert newTransacrionType;
        
        Requested_For__c newRequestedFor = new Requested_For__c();
        newRequestedFor.isActive__c = True;
        newRequestedFor.Type__c = 'Vehicle';
        newRequestedFor.Name = 'Ajman Traffic Department';
        insert newRequestedFor;
        
        RecordType requestRecordType = [SELECT Id FROM RecordType WHERE SObjectType = 'Request__c' AND DeveloperName LIKE '%Certificate%' LIMIT 1];
        newRequest = new Request__c();
        newRequest.RecordTypeId = requestRecordType.Id;
        newRequest.Company__c = newAccount.Id;
        newRequest.Transaction_Type__c = newTransacrionType.Id;
        newRequest.Delivery_Method__c = 'Self Pickup';
        newRequest.PRO_Mobile_No__c  = '22ss';
        newRequest.Submission_Channel__c  = 'Mobile App';
        newRequest.Request_Status__c = 'Under Proccess';
        //newRequest.Requested_For__c = newRequestedFor.Id;
        insert newRequest;
        
        newRequest = [SELECT Id, Name FROM Request__c WHERE Id = :newRequest.id];

        SLA__c newSLA = new SLA__c();
        newSLA.Request__c = newRequest.Id;
        insert newSLA;
        /*
		[SELECT ID, isCompleted__c, Actual_End_Date_Time__c, Actual_Start_Date_Time__c, Amendment__c, 
         Application_Type__c, Expected_End_Date__c,isCancelled__c, Process_Type__c, SLA_Hours__c, 
         Status__c, Request__c 
         FROM SLA__c 
         where Request__c IN: slaCancelledMap.keyset() 
         OR Request__c IN: slaCompletedMap.keyset() 
         ORDER BY CreatedDate])
		*/
    }
    
    // Methods for testing
    public static testMethod void testMobileAppRequestSearchExtension() 
    {
        createData();
        
        MobileAppRequestSearchExtension.searchRequests(newRequest.Name);
        //newRequest = new Request__c();
        
        PageReference pageRef = Page.MobileApp_Request_Search;   
        Test.setCurrentPage(pageRef);        
        
        ApexPages.currentPage().getParameters().put('requestNumber', newRequest.Id);
        
        ApexPages.StandardController requestStandardController = new ApexPages.StandardController(newRequest);
        MobileAppRequestSearchExtension requestExtension = new MobileAppRequestSearchExtension(requestStandardController);
        
        
        //Testing trg_Request
        newRequest.Request_Status__c = 'Cancelled';
        update newRequest;
        
        newRequest.Request_Status__c = 'Approved by Back Office Manager';
        newRequest.Request_Status__c = 'Scheduled for Delivery';
        update newRequest;
    }
}